<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8"></meta>
	<title>数据字典展示</title>
	<!-- Editor css... -->
	<link rel="stylesheet" href="Editor/css/editormd.css" />
	<link rel="stylesheet" href="Editor/css/editormd.preview.min.css" />
	<!-- Editor js -->
	<script src="Editor/js/jquery.min.js"></script>
	<script src="Editor/js/editormd.min.js"></script>
	<script src="Editor/lib/marked.min.js"></script>
	<script src="Editor/lib/prettify.min.js"></script>
</head>
<body>
<div>
    <h1>在线Markdown</h1>
	<span>数据库：</span><select id="DatabaseName">
</select>
    <a id="export" href="/download" target="_blank" style="float:right">下载PDF</a>
</div>
<!-- Editor 容器 -->
<div class="content editormd-preview-theme" id="content">
    <textarea id="markdown" style="display:none;" th:text="${markdown}"></textarea>
</div>
<!-- Editor markdown转html -->
<script type="text/javascript">
    window.onload = function(){
        var ip=sessionStorage.getItem("ip");
        var port=sessionStorage.getItem("port");
        var database=sessionStorage.getItem("database");
        var username=sessionStorage.getItem("username");
        var password=sessionStorage.getItem("password");
        var selector=sessionStorage.getItem("selector");
        var d=document.getElementById("export");
        d.href="/download?ip="+ip+"&port="+port+"&database="+database+"&username="+username+"&password="+password+"&selector="+selector;
        var data={}
        data.ip=ip;
        data.port=port;
        data.database=database;
        data.username=username;
        data.password=password;
        data.selector=selector;
        console.info(data);
        var url="/getDataBaseNameList";
        $.post(url,data,function(result){
            console.info(result);
            $.each(result,function(i){
                $("#DatabaseName").append("<option value ="+result[i]+">"+result[i]+"</option>")
            })

            $("#DatabaseName").find("option[value='"+database+"']").attr("selected",true);
        });

    }
    $("#DatabaseName").bind("change",function(){

        var ip=sessionStorage.getItem("ip");
        var port=sessionStorage.getItem("port");
        var database=$("#DatabaseName").val()
        sessionStorage.setItem("database",database);
        var username=sessionStorage.getItem("username");
        var password=sessionStorage.getItem("password");
        var selector=sessionStorage.getItem("selector");

        var d=document.getElementById("export");
        d.href="/download?ip="+ip+"&port="+port+"&database="+database+"&username="+username+"&password="+password+"&selector="+selector;

        var data={}
        data.ip=ip;
        data.port=port;
        data.database=database;
        data.username=username;
        data.password=password;
        data.selector=selector;
        var url="/getMarkdownString";
        $.post(url,data,function(result){
            $("#content").html('<textarea id="markdown" style="display:none;"></textarea>');
            $('#markdown').val("");
            $('#markdown').val(result);
            editormd.markdownToHTML("content",{emoji:true});
        });

    });
</script>
<script>
    editormd.markdownToHTML("content",{emoji:true});
</script>


</body>
</html>